package com.ruoyi.controller.middlesign.timing;

import com.alibaba.fastjson.JSON;
import com.ruoyi.controller.middlesign.MiddlesMethod;
import com.ruoyi.service.middlesign.MiddlesignService;
import com.ruoyi.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zeo
 * @explain 定时B2803查询B2803授信  B2804、B2805、B2806、B2807推送
 * @date 2021/3/16 10:35
 */
@Component
public class San {

    @Autowired
    MiddlesignService middlesignService;

    public void san() {
        //查询数据库中的核心企业集合
        List<Map<String, Object>> hxqyList = middlesignService.findHxqyList();
        for (Map map : hxqyList) {
            //获取核心企业的名称和统一社会代码
            String hxqyName = map.get("name").toString();
            String hxqyCode = map.get("code").toString();

            //这个List用来存储B2803返回的授信息集合
            List<Map<String, Object>> maps = MiddlesMethod.getCreditList(hxqyCode,hxqyName);

            if (maps.size() > 0) {
                for (Map map1 : maps) {
                    //取出供应商名称
                    String CREDIT_NAME = map1.get("CREDIT_NAME").toString();
                    //取出供应商社会信用代码
                    String CREDIT_CODE = map1.get("CREDIT_CODE").toString();

                    Map map2 = new HashMap();
                    map2.put("CREDIT_NAME", CREDIT_NAME);
                    map2.put("hxqyName", hxqyName);


                    //推2804
                    middlesignService.insertAccountsByName(CREDIT_NAME, hxqyName);
                    List<Map<String, Object>> maps1 = middlesignService.findAccountsByName(map2);
                    //转换成jsonString
                    String jsonString = JSON.toJSONString(maps1);
                    BaseResult baseResult = middlesignService.accountsPushData(jsonString, CREDIT_CODE, CREDIT_NAME, hxqyCode,"time");
                    System.out.println(baseResult);

                    //推2805
                    middlesignService.insertPaymentByName(CREDIT_NAME, hxqyName);
                    List<Map<String, Object>> maps2 = middlesignService.findPaymentByName(map2);
                    //转换成jsonString
                    String jsonString1 = JSON.toJSONString(maps2);
                    BaseResult baseResult2 = middlesignService.paymentPushData(jsonString1, CREDIT_CODE, CREDIT_NAME, hxqyCode,"time");
                    System.out.println(baseResult2);

                    //推2806
                    middlesignService.insertStockSupplierAccount(CREDIT_NAME);
                    List<Map<String, Object>> maps3 = middlesignService.findStockSupplierAccount(CREDIT_NAME);
                    //转换成jsonString
                    String jsonString2 = JSON.toJSONString(maps3);
                    BaseResult baseResult3 = middlesignService.supplierPush(jsonString2,CREDIT_CODE,hxqyCode,"time");
                    System.out.println(baseResult3);

                    //推B2807
                    middlesignService.insertReconciliationData(CREDIT_NAME, hxqyName);
                    List<Map<String, Object>> maps4 = middlesignService.findReconciliationData(map2);
                    //转换成jsonString
                    String jsonString3 = JSON.toJSONString(maps4);
                    BaseResult baseResult4 = middlesignService.reconciliationDataPush(jsonString3, CREDIT_CODE, CREDIT_NAME, hxqyCode,"time");
                    System.out.println(baseResult4);
                }
            }
        }
    }
}
